<template>
  <div>
    <h1>第三题</h1>
    <h2>{{ num }}</h2>
    <button @click="sumFn">求和</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      num: "",
      arr: [
        {
          name: "小明",
          age: 18,
        },
        {
          name: "小花",
          age: 25,
        },
        {
          name: "小爱",
          age: 21,
        },
      ],
    };
  },
  methods: {
    sumFn() {
      this.arr.forEach((item) => {
        this.num = +this.num + +item.age;
      });
    },
  },
};
</script>

<style>
</style>
